/*
 * 
 */
package fr.univtln.superplanning.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;

import fr.univtln.superplanning.api.ISuperplanningManager;
import fr.univtln.superplanning.gui.MainWindow;

/**
 * This controller manage all the Planning Viewer. It's contains small
 * controller that controll the component of the Planning viewer.
 * 
 * @author vincent
 * 
 */
public class MainWindowController implements ActionListener, IGenericController {

	/** The db login view. */
	private MainWindow mainWindow; // view

	/** The superplanning manager. */
	private ISuperplanningManager superplanningManager;

	private PersonTypeController personTypeController;
	private PersonManagerController personManagerController;
	private SectionController sectionController;
	private PromotionController promotionController;
	private EventController eventController;
	private PlanningViewerController planningViewerController;
	private TeachingController teachingController;

	public MainWindowController(ISuperplanningManager superplanningManager) {
		this.superplanningManager = superplanningManager;
		this.mainWindow = new MainWindow(this);
		initializeController();

		initializeUi();
	}

	private void initializeController() {
		// All subcontrollers

		// For the moment, the models are nulls.
		personTypeController = new PersonTypeController(superplanningManager, mainWindow, null);
		sectionController = new SectionController(superplanningManager, mainWindow, null);
		personManagerController = new PersonManagerController(superplanningManager, mainWindow);
		promotionController = new PromotionController(superplanningManager, mainWindow, null);
		teachingController = new TeachingController(superplanningManager, mainWindow, null);
		// planningViewerController = new
		// PlanningViewerController(superplanningManager);
		// eventController = new EventController(superplanningManager, null);
	}

	private void initializeUi() {
		mainWindow.initializeListeners();
		mainWindow.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

	}

	public MainWindow getMainWindow() {
		return mainWindow;
	}

	public void setMainWindow(MainWindow mainWindow) {
		this.mainWindow = mainWindow;
	}

	public ISuperplanningManager getSuperplanningManager() {
		return superplanningManager;
	}

	public void setSuperplanningManager(ISuperplanningManager superplanningManager) {
		this.superplanningManager = superplanningManager;
	}

	public void updateUi() {
		personTypeController.updateUi();
		personManagerController.updateUi();
		sectionController.updateUi();
		promotionController.updateUi();
		teachingController.updateUi();

	}

	public PersonTypeController getPersonTypeController() {
		return personTypeController;
	}

	public void setPersonTypeController(PersonTypeController personTypeController) {
		this.personTypeController = personTypeController;
	}

	public PersonManagerController getPersonManagerController() {
		return personManagerController;
	}

	public void setPersonManagerController(PersonManagerController personManagerController) {
		this.personManagerController = personManagerController;
	}

	public SectionController getSectionController() {
		return sectionController;
	}

	public void setSectionController(SectionController sectionController) {
		this.sectionController = sectionController;
	}

	public PromotionController getPromotionController() {
		return promotionController;
	}

	public void setPromotionController(PromotionController promotionController) {
		this.promotionController = promotionController;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub

	}

}
